package com.crm.system.controller.coursearrange;

import com.crm.common.model.DataResponse;
import com.crm.common.model.DhPageInfo;
import com.crm.common.model.DhResponse;
import com.crm.common.model.Enum.ResponseCodeEnum;
import com.crm.model.qo.courseregist.*;
import com.crm.model.vo.courseregist.*;
import com.crm.system.service.coursearrange.CourseArrangeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @Description: 课程管理
 * @Author lixq-f
 * @Date 2021/4/25
 * @Version V1.0
 **/
@RequestMapping("/courseArrange")
@RestController
public class CourseArrangeController {

    @Autowired
    private CourseArrangeService courseArrangeService;

    /**
     * @Description: 课程管理列表
     * @Param: [pageIndex, pageSize, sortName, sortOrder]
     * @Return: com.crm.common.model.DataResponse
     * @Author: lixq-f
     * @Date: 2021/4/26
     **/
    @GetMapping("/getCourseManagerList")
    public DataResponse getCourseManagerList(@RequestParam(value = "pageIndex", required = false, defaultValue = "1") Integer pageIndex,
                                             @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                             @RequestParam(value = "sortName", required = false) String sortName,//排序列名
                                             @RequestParam(value = "sortOrder", required = false) String sortOrder,//排序规则，asc、desc
                                             CourseListQO courseListQO) {
        DhPageInfo<CourseListVO> dhPageInfo = courseArrangeService.getCourseList(pageIndex, pageSize, sortName, sortOrder, courseListQO);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), dhPageInfo);
    }


    /**
     * @Description: 添加报名
     * @Param: [registQO]
     * @Return: com.crm.common.model.DataResponse
     * @Author: lixq-f
     * @Date: 2021/4/29
     **/
    @PostMapping("/addCourseRegist")
    public DataResponse addCourseRegist(@Valid @RequestBody CourseRegistQO registQO) {
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), courseArrangeService.insert(registQO));
    }


    /**
     * @Description: 申请试听
     * @Param: []
     * @Return: com.crm.common.model.DataResponse
     * @Author: lixq-f
     * @Date: 2021/7/26
    **/
    @PostMapping("/addCourseTryListen")
    public DataResponse addCourseTryListen(@Valid @RequestBody CourseTryListenVO courseTryListenVO){
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),courseArrangeService.addCourseTryListen(courseTryListenVO));
    }



    /**
     * @Description: 课程报名列表
     * @Param: [pageIndex, pageSize, sortName, sortOrder]
     * @Return: com.crm.common.model.DataResponse
     * @Author: lixq-f
     * @Date: 2021/4/29
     **/
    @GetMapping("/selectRegistList")
    public DataResponse selectCourseRegistList(@RequestParam(value = "pageIndex", required = false, defaultValue = "1") Integer pageIndex,
                                               @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                               @RequestParam(value = "sortName", required = false) String sortName,
                                               @RequestParam(value = "sortOrder", required = false) String sortOrder,
                                               CourseRegistListQO registListQO) {
        DhPageInfo<CourseRegistVO> dhPageInfo = courseArrangeService.selectCourseRegistList(pageIndex, pageSize,
                sortName, sortOrder, registListQO);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), dhPageInfo);
    }


    /**
     * @Description: 审核报名列表
     * @Param: [pageIndex, pageSize, sortName, sortOrder, registListQO]
     * @Return: com.crm.common.model.DataResponse
     * @Author: lixq-f
     * @Date: 2021/7/15
    **/
    @PostMapping("/selectAuditRegistList")
    public DataResponse selectAuditRegistList(@RequestParam(value = "pageIndex", required = false, defaultValue = "1") Integer pageIndex,
                                              @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                              @RequestParam(value = "sortName", required = false) String sortName,
                                              @RequestParam(value = "sortOrder", required = false) String sortOrder,
                                              AuditRegistListQO registListQO) {
        DhPageInfo<AuditRegistListVO> dhPageInfo = courseArrangeService.selectAuditRegistList(pageIndex, pageSize, sortName, sortOrder, registListQO);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), dhPageInfo);
    }


    /**
     * @Description: 取消
     * @Param: [id]
     * @Return: com.crm.common.model.DataResponse
     * @Author: lixq-f
     * @Date: 2021/4/29
     **/
    @PostMapping("/delCourseRegist")
    public DataResponse deleteCourseRegist(@RequestParam(value = "registId", required = false) String registId,
                                           @RequestParam(value = "courseId", required = false) String courseId) {
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), courseArrangeService.deleteById(registId, courseId));
    }


    /**
     * @Description: 根据客户ID、课程ID获取报名人
     * @Param: [customerId, courseId]
     * @Return: com.crm.common.model.DataResponse
     * @Author: lixq-f
     * @Date: 2021/6/10
     **/
    @GetMapping("/getRegistByCourseIdAndCustomerId")
    public DataResponse getRegistByCourseIdAndCustomerId(@RequestParam(value = "customerId") String customerId,
                                                         @RequestParam(value = "courseId") String courseId) {

        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),
                courseArrangeService.getRegistByCourseIdAndCustomerId(customerId, courseId));
    }


    /**
     * @Description: 根据ID获取报名人信息
     * @Param: [id]
     * @Return: com.crm.common.model.DataResponse
     * @Author: lixq-f
     * @Date: 2021/5/10
     **/
    @GetMapping("/getRegistById/{id}")
    public DataResponse getCourseRegistById(@PathVariable(value = "id") String id) {
        CourseRegistVO reg = courseArrangeService.selectCourseRegById(id);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), reg);
    }


    /**
     * @Description: 编辑报名
     * @Param: [registQO]
     * @Return: com.crm.common.model.DataResponse
     * @Author: lixq-f
     * @Date: 2021/4/29
     **/
    @PostMapping("/updateCourseRegist")
    public DataResponse updateCourseRegist(@Valid @RequestBody EditCourseRegistQO registQO) {
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), courseArrangeService.update(registQO));
    }


    /**
     * @Description: 审核取消
     * @Param: [cancelQO]
     * @Return: com.crm.common.model.DataResponse
     * @Author: lixq-f
     * @Date: 2021/6/9
     **/
    @PostMapping("/auditCancel")
    public DataResponse auditCancel(@Valid @RequestBody AuditCancelVO cancelVO) {
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), courseArrangeService.auditCancel(cancelVO));
    }


    /**
     * @Description: 报名审核-扣次
     * @Param: []
     * @Return: com.crm.common.model.DataResponse
     * @Author: lixq-f
     * @Date: 2021/6/10
     **/
    @PostMapping("/courseConsume")
    public DataResponse courseConsume(@RequestBody CourseConsumeVO consumeVO) {
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), courseArrangeService.courseConsume(consumeVO));
    }


    /**
     * @Description: 生成二维码
     * @Param: []
     * @Return: com.crm.common.model.DataResponse
     * @Author: lixq-f
     * @Date: 2021/7/12
     **/
    @PostMapping("/generateQrCode")
    public DataResponse generateQrCode() {
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), courseArrangeService.generateQrCode());
    }


}
